#include <iostream>
#include <stack>
using namespace std;

int calculate(string s) {
    stack<int> st;
    int num = 0;
    int result = 0;
    int sign = 1;

    for (int i = 0; i < s.length(); i++) {
        char c = s[i];
        if (isdigit(c)) {
            num = num * 10 + (c - '0');
        } else if (c == '+' || c == '-') {
            result += sign * num;
            num = 0;
            sign = (c == '+') ? 1 : -1;
        } else if (c == '(') {
            st.push(result);
            st.push(sign);
            result = 0;
            sign = 1;
        } else if (c == ')') {
            result += sign * num;
            num = 0;
            result *= st.top();
            st.pop();
            result += st.top();
            st.pop();
        }
    }

    return result + (sign * num);
}

int main() {
    string s = "(1+(4+5+2)-3)+(6+8)";

    int result = calculate(s);
    cout << "Result: " << result << endl;

    return 0;
}